<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <script src="../layui/layui.js"></script>
    <script src="../js/jquery.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <style type="text/css">
        html,body{
            width: 100%;
            height: 100%;
            margin: 0;
        }
    </style>
    <script>
        $(function () {
            $.get('../adminInfo',function(data){
                if(data == '0'){
                    alert("请先登录！")
                    top.location.href='./login.html'
                }
            },"json")
        })
    </script>
</head>
<body>
<div style="margin-right: 15px">
    <!-- 内容主体区域 -->
    <div>
        当前位置：
        <span class="layui-breadcrumb" lay-separator=" > " style="visibility: visible;">
            <a href="shouye.html">首页 > </a>
            <a><cite>用户管理</cite></a>
        </span>
    </div>
    <div>
        <div style="clear:both;">
            <table class="layui-hide" id="test" lay-filter="test"></table>
        </div>
    </div>

</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>
<script>

    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test'
            , url: '../selUser'
            , title: '用户表'
            , cols: [[
                {field: 'id', title: '序号', width: 100}
                , {field: 'name', title: '姓名', width: 200}
                , {field: 'email', title: '邮箱', width: 200}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该用户信息吗？', function (index) {
                    $.get('../delUser', {'id': data.id}, function (result) {
                        if (result > 0) {
                            alert("删除成功！");
                            window.location.href='./user.html'
                        }else{
                            alert("删除失败！");
                            window.location.href='./user.html'
                        }
                    })
                });
            }
        });
    });
</script>
</body>
</html>